﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MDF.DataHelper.BussinessObject.UsersBO;
using System.Data;
using MDF.DataHelper.DataObject.UsersDO;
using MDF.Utilites.Tools;

namespace MDF.DataHelper.BussinessLogic.UsersBL
{
    public class UserMembershipBUS : BaseBussinessLogic
    {

        #region staticMember
        /// <summary>
        /// 
        /// </summary>
        private static UserMembershipBUS _instance;
        /// <summary>
        /// 
        /// </summary>
        public static UserMembershipBUS Current
        {
            get { return _instance == null ? _instance = new UserMembershipBUS() : _instance; }
        }
        #endregion

        #region Method

        public UserMembership GetByUsername(string _strUsername)
        {
            DataTable dt = new DataTable();
            UserMembershipDAO objResaleDAO = new UserMembershipDAO(this.m_objData);
            dt = objResaleDAO.GetByUsername(_strUsername);
            var lstTemp = dt.ToObject<UserMembership>();
            return lstTemp;
        }
         
        public void Update(int UserId, string Password, string PasswordSalt)
        {
            UserMembershipDAO objResaleDAO = new UserMembershipDAO(this.m_objData);
            Random r = new Random();
            PasswordSalt = r.Next(1000, 9999).ToString();
            Password = MDF.Utilites.Tools.CommonMethods.Encrypt(Password + PasswordSalt);
            objResaleDAO.Update(UserId, Password, PasswordSalt);
        }

        #endregion

        public UserMembership GetByUserID(int UserID)
        {
            DataTable dt = new DataTable();
            UserMembershipDAO objResaleDAO = new UserMembershipDAO(this.m_objData);
            dt = objResaleDAO.GetByUserID(UserID);
            var lstTemp = dt.ToObject<UserMembership>();
            return lstTemp;
        }

        public void UpdateActive(int UserID, bool IsConfirm, int UpdatedUser)
        {
            UserMembershipDAO objResaleDAO = new UserMembershipDAO(this.m_objData);
            objResaleDAO.UpdateActive(UserID, IsConfirm, UpdatedUser);
        }

    }
}